CC=gcc
CFLAGS=-W -Wall #-std=c99 -ansi -pedantic
LDFLAGS=-lcrypto
STRIP=strip
OUTDIR=bin/x86

ifeq ($(ARM),yes)
	CROSSDIR=/opt/emlix/netdcu10/
	CC=$(CROSSDIR)bin/arm-linux-gcc
	LDFLAGS+=-L$(CROSSDIR)lib -L$(CROSSDIR)libexec -min_array_alignment=1 
	STRIP=$(CROSSDIR)bin/arm-linux-strip
	OUTDIR=bin/arm
endif

ifeq ($(DEBUG),yes)
	CFLAGS+=-O0 -g
	OUTDIR:=$(OUTDIR)_debug
else
	CFLAGS+=-O3
endif

# Files
OSRCS=main.c
OOBJS=$(addprefix $(OUTDIR)/, $(OSRCS:.c=.o))

ifeq ($(ARM),yes)
all: md5bsum
ifneq ($(DEBUG),yes)
	$(STRIP) $(OUTDIR)/md5bsum
endif
else
all: md5bsum
ifneq ($(DEBUG),yes)
	$(STRIP) $(OUTDIR)/md5bsum
endif
endif

md5bsum: $(OOBJS)
	$(CC) -o $(OUTDIR)/$@ $^ $(LDFLAGS)

$(OUTDIR)/%.o: %.c
	$(CC) -o $@ -c $< $(CFLAGS)
	
.PHONY: clean

clean:
	rm -f $(OOBJS)
	
mrproper: clean
	rm -f $(OUTDIR)/md5bsum

